<?php

namespace application\openapi\models\cars;

use application\openapi\models\BaseInput;
use peng\enums\DBOperator;

/**
 * 车辆
 *
 * @author peng.huang
 */
class Save extends BaseInput {

    /**
     * 操作类型[A=新增、U=修改、D=删除]
     * 
     * @var string 
     */
    public $operator = DBOperator::INSERT;

    /**
     * 自增ID
     * 
     * @var int 
     */
    public $id = 0;

    /**
     * 用户id
     * 
     * @var int 
     */
    public $userid = 0;

    /**
     * 车牌号
     * 
     * @var string 
     */
    public $carno;

    /**
     * 车类型
     * 
     * @var string 
     */
    public $cartype;

    /**
     * 车长
     * 
     * @var string 
     */
    public $carlength;

    /**
     * 车载重
     * 
     * @var string 
     */
    public $carweight;

    /**
     * 车体积
     * 
     * @var string 
     */
    public $carsequare;

    /**
     * 联系人
     * 
     * @var string 
     */
    public $carlinker;

    /**
     * 联系电话
     * 
     * @var string 
     */
    public $carphone;

    /**
     * 车辆购买时间
     * 
     * @var date 
     */
    public $carstartdate;

    /**
     * 车辆照片
     * 
     * @var string 
     */
    public $carpic;

    /**
     * 车辆状态[0=有效、1=出车中、2=已删除、3=已超过使用年限]
     * 
     * @var int 
     */
    public $carstatus = 0;

    /**
     * 构造函数
     */
    public function __construct() {
        $this->carstartdate = date('Y-m-d');
    }

    /**
     * 规则
     * 
     * @return array
     */
    public function rules() {
        return array(
            array('operator', 'in', 'range' => array(DBOperator::INSERT, DBOperator::UPDATE, DBOperator::DELETE)),
            array(array('userid'), 'required'),
            array(array('id', 'userid'), 'int'),
            array(array('carno'), 'required', 'onWhen' => array($this, 'isSaved')),
            array(array('carstartdate'), 'date', 'onWhen' => array($this, 'isSaved')),
            array(array('carstatus'), 'in', 'range' => array(0, 1, 2, 3), 'onWhen' => array($this, 'isSaved')),
        );
    }

    /**
     * 属性名称
     * 
     * @return array
     */
    public function attrLabels() {
        return array(
            'operator' => '操作类型',
            'id' => 'ID',
            'userid' => '用户ID',
            'carno' => '车牌号',
            'carstartdate' => '车辆购买时间',
            'carstatus' => '车辆状态',
        );
    }

}
